import socket
from ssl import wrap_socket, DER_cert_to_PEM_cert, PROTOCOL_SSLv3
import config

def get_server_certificate(addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None):
    host, port = addr
    quick_sock = socket.socket()
    quick_sock.settimeout(config.timeout)
    s = wrap_socket(quick_sock, ssl_version=ssl_version)
    s.connect(addr)
    dercert = s.getpeercert(True)
    s.close()
    return DER_cert_to_PEM_cert(dercert)